package com.michale.common.result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.michale.common.character.ClassConvert;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author Michale
 * @apiNote 分页-标准返回结果
 */
@Data
@NoArgsConstructor
public class PageResult implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "总记录数")
    private int totalCount;

    @ApiModelProperty(value = "每页记录数")
    private int pageSize;

    @ApiModelProperty(value = "总页数")
    private int totalPage;

    @ApiModelProperty(value = "当前页数")
    private int currPage;

    @ApiModelProperty(value = "列表数据")
    private List<?> list;

    public PageResult(IPage<?> page) {
        this.list = page.getRecords();
        this.totalCount = ClassConvert.toInt(page.getTotal());
        this.pageSize = ClassConvert.toInt(page.getSize());
        this.currPage = ClassConvert.toInt(page.getCurrent());
        this.totalPage = ClassConvert.toInt(page.getPages());
    }
}
